import router from "../router";
import store from "../store";
import cookie from "@utils/store/cookie";
import { isWeixin } from "@utils";
import { oAuth } from "@libs/wechat";

export default function toLogin(push, backUrl) {
  store.commit("LOGOUT");
  
  const { fullPath, name } = router.currentRoute;
  if (isWeixin()){
    if(cookie.get('login_back_url')){
      console.log(1222);
    }else{
      cookie.set("login_back_url", backUrl || fullPath);
    }
   
  }else{
    cookie.set("login_back_url", backUrl || fullPath);
  }
  // if (isWeixin()) {
  //   console.log('0')
  //    //oAuth();

  // } else {
    if (name !== "Login") {
      if(cookie.get('from1')){
        if(cookie.get('from1')=='app' || cookie.get('from1').indexOf('3Dapp')!= '-1'){
          cookie.set('from1','app');
          var u = navigator.userAgent, app = navigator.appVersion;
          var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
          var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
          var win = window;
          var obj={
              "action": "goToLogin",
              "content": {}
          }
          if (isAndroid) {
              App.onAppResponse(JSON.stringify(obj));
          }
          if (isIOS) {
              win.webkit.messageHandlers.onAppResponse.postMessage(JSON.stringify(obj));
          }  
        }else{
          console.log(111);
          push
            ? router.push({ path: "/login" })
            : router.replace({ path: "/login" });
        }
      }
      else{
        console.log(111);
        push
          ? router.push({ path: "/login" })
          : router.replace({ path: "/login" });
      }
    }
  // }
}
